<?php

namespace App\Listeners;

use App\Events\PushUserLogEvent;
use App\Models\UserLog;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;


class PushUserLogListener implements ShouldQueue
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {

    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        //
    }

    public function add(PushUserLogEvent $event){

        $logs = UserLog::createInstance(
            $event->type,
            $event->user_id,
            $event->operation,
            $event->before,
            $event->after,
            $event->remark,
            $event->staff_ip,
            $event->staff_id
        );
        $logs->save();
    }
    public function subscribe(Dispatcher $events)
    {
        $events->listen(
            'App\Events\PushUserLogEvent',
            'App\Listeners\PushUserLogListener@add'
        );

    }
}
